# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
#
# TODO: Separate packages into subpackages?
# TODO: Install even packages from the full tarball?
# TODO: Figure out how to run tests.
pkgname=racket
pkgver=7.7
pkgrel=0
pkgdesc="A general purpose programming language in the Lisp-Scheme family"
url="https://racket-lang.org/"
arch="all"
license="LGPL-3.0-or-later MIT"
depends="ca-certificates libcrypto1.1 libssl1.1"
makedepends="chrpath libffi-dev libucontext-dev"
subpackages="$pkgname-dev $pkgname-doc"
source="https://download.racket-lang.org/releases/$pkgver/installers/racket-minimal-$pkgver-src.tgz
	0001-Ensure-that-the-GMP-ARM-extra-file-has-the-correct-e.patch"

# XXX: Upstream repository uses a racket/ subdirectory, this can be
# removed if the aport builds without any git format patches.
patch_args="-p2"

prepare() {
	default_prepare
	# Remove bundled libffi to be sure that system-provided is used.
	rm -Rf src/foreign/libffi
}

build() {
	cd "$builddir"/src

	export CFLAGS="$CFLAGS -D_GNU_SOURCE"
	export LDFLAGS="$LDFLAGS -lucontext"
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--target=$CTARGET \
		--prefix=/usr \
		--sysconfdir=/etc \
		--enable-shared \
		--disable-docs
	make
}

package() {
	cd "$builddir"/src

	make install DESTDIR="$pkgdir"

	cd "$pkgdir"

	# Remove redundant RPATH.
	chrpath -d usr/bin/racket usr/lib/racket/gracket

	rm -Rf usr/share/applications
}

sha512sums="e683a2f90dc2f0a0f73d07319f9241359c85593d2e227183c604fa60c734bc922a0c184cae4934dc04f71b889f433c40902098b02c03078a3da8bb0a10c24e30  racket-minimal-7.7-src.tgz
ce29c2761ad69b8f9415e23080fa607bd45e8e8ac76394d8fde1e9f022aa58374651ebf3576de88c1280a3aeaae4c9921eaa66d3a950943eec4fe1528f10311a  0001-Ensure-that-the-GMP-ARM-extra-file-has-the-correct-e.patch"
